package com.dodoke.common.config;

import com.dodoke.common.constant.Constants;
import com.dodoke.common.utils.ip.IpUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component("CustomServerConfig")
public class ServerConfig {

    @Value("${server.port}")
    private String port;

    @Value("${server.servlet.context-path}")
    private String contextPath;

    private static final String IP = IpUtils.getHostIp();

    public static String getIP() {
        return IP;
    }

    public String getPort() {
        return port;
    }

    public void setPort(String port) {
        this.port = port;
    }

    public String getContextPath() {
        return contextPath;
    }

    public void setContextPath(String contextPath) {
        this.contextPath = contextPath;
    }

    /** 返回完整项目路径 */
    public String wholeProjectUrl() {
        StringBuilder stringBuilder = new StringBuilder();
        return stringBuilder.append(Constants.HTTP)
                .append(getIP())
                .append(":")
                .append(port)
                .append(contextPath).toString();

    }
}
